<html>
<head><meta charset="utf-8"><title>Add allow-by-default lints for all attributes with unsafe be · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html">Add allow-by-default lints for all attributes with unsafe be</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227687028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227687028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227687028">(Feb 24 2021 at 22:38)</a>:</h4>
<p>So I'm hoping it's possible to fully tame <code>unsafe</code> hiding behind attributes: <a href="https://github.com/rust-lang/rust/issues/82499">https://github.com/rust-lang/rust/issues/82499</a></p>



<a name="227745036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227745036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227745036">(Feb 25 2021 at 10:14)</a>:</h4>
<p>As the <code>#[link]</code> attribute is considered unsafe, should the <code>-l</code> flag be covered too?</p>
<div class="codehilite"><pre><span></span><code>    -l [KIND=]NAME      Link the generated crate(s) to the specified native
                        library NAME. The optional KIND can be one of
                        static, framework, or dylib (the default).
</code></pre></div>



<a name="227745443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227745443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227745443">(Feb 25 2021 at 10:18)</a>:</h4>
<p>(It's not an attribute though.)</p>



<a name="227800761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227800761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227800761">(Feb 25 2021 at 17:02)</a>:</h4>
<p>code can't block the command line arguments passed to compile it.</p>
<p>also link can only link to unsafe functions so it's "no worse than already having a bunch of unsafe functions", which is a common phrase that i definitely didn't just make up.</p>



<a name="227803590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227803590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227803590">(Feb 25 2021 at 17:20)</a>:</h4>
<blockquote>
<p>code can't block the command line arguments passed to compile it.</p>
</blockquote>
<p>Do you mean the compiler can't fire the lint for the <code>-l</code> flag? If so, why?</p>



<a name="227804283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227804283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227804283">(Feb 25 2021 at 17:25)</a>:</h4>
<blockquote>
<p>also link can only link to unsafe functions so it's "no worse than already having a bunch of unsafe functions", which is a common phrase that i definitely didn't just make up.</p>
</blockquote>
<p>It was mentioned on the thread, but it may link to a library that has an init or fini table, or that otherwise has startup or finalization behaviour.</p>



<a name="227807459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227807459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227807459">(Feb 25 2021 at 17:44)</a>:</h4>
<p><span class="user-mention" data-user-id="374396">@hyd-dev</span> I suppose I should say that code is not currently capable of doing that. It's not unthinkable that things could be changed.</p>



<a name="227807534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227807534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227807534">(Feb 25 2021 at 17:45)</a>:</h4>
<p>I guess... the linker is already something you have to completely trust. Like if your linker is hostile to you, you're sunk.</p>



<a name="227807582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227807582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227807582">(Feb 25 2021 at 17:45)</a>:</h4>
<p>i don't think trying to regulate that is helpful</p>



<a name="227809805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227809805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227809805">(Feb 25 2021 at 18:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be/near/227807534">said</a>:</p>
<blockquote>
<p>I guess... the linker is already something you have to completely trust. Like if your linker is hostile to you, you're sunk.</p>
</blockquote>
<p>Yes... Linkers are out of control.</p>
<p>That reminds me about <a href="https://github.com/rust-lang/rust/issues/29596"><code>#[link_args]</code></a>. Should that (and maybe also <code>-C link-arg(s)</code>) be added to the list?</p>



<a name="227810790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227810790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227810790">(Feb 25 2021 at 18:07)</a>:</h4>
<p>linking to libraries or controlling the linker behaviour through attributes is pretty weird though. Even if I suspected linker shenanigans, I would probably look there last. OTOH, <code>#[link]</code> is pretty much compulsory if you want to refer to library symbols via <code>extern {}</code> <a href="https://github.com/rust-lang/rust/issues/65610">*correctly*</a>.</p>



<a name="227813569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227813569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227813569">(Feb 25 2021 at 18:27)</a>:</h4>
<blockquote>
<p>linking to libraries or controlling the linker behaviour through attributes is pretty weird though.</p>
</blockquote>
<p>Personally I think <code>#[link]</code> is convenience, especially when you don't want to write/<a href="https://github.com/rust-lang/rust/pull/78924">have</a> a (large) build script.</p>



<a name="227814909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227814909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227814909">(Feb 25 2021 at 18:36)</a>:</h4>
<p>Anyway I am able to achieve the result of <code>#[link]</code> via <code>#[link_args]</code>: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=9f7415ccaefc15c7d471067bed0ce881">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=9f7415ccaefc15c7d471067bed0ce881</a><br>
So <span class="user-mention" data-user-id="132721">@Tony Arcieri</span>, could you add that to the list? It's an <em>unstable</em> attribute though.</p>



<a name="227834391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/227834391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#227834391">(Feb 25 2021 at 20:35)</a>:</h4>
<p><span class="user-mention" data-user-id="374396">@hyd-dev</span> done</p>



<a name="228056650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/228056650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#228056650">(Feb 27 2021 at 12:52)</a>:</h4>
<p>So if I understand correctly, this is not adding new allow-by-default lints but it is extending the existing allow-by-default <code>unsafe_code</code> lint? The PR does the latter (I think) but the issue (and Zulip topic title) describes the former so I am a bit confused.^^</p>



<a name="228056688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/228056688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#228056688">(Feb 27 2021 at 12:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="132721">Tony Arcieri</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be/near/227687028">said</a>:</p>
<blockquote>
<p>So I'm hoping it's possible to fully tame <code>unsafe</code> hiding behind attributes</p>
</blockquote>
<p>I love the progress, but I think to "fully tame" it, an allow-by-default lint is not enough... after all we also don't make <code>unsafe</code> fn calls in safe code an allow-by-default lint. Do you have any ideas/plans for how to move forward beyond allow-by-default?</p>



<a name="234275572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add%20allow-by-default%20lints%20for%20all%20attributes%20with%20unsafe%20be/near/234275572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be.html#234275572">(Apr 13 2021 at 06:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="374396">hyd-dev</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Add.20allow-by-default.20lints.20for.20all.20attributes.20with.20unsafe.20be/near/227814909">said</a>:</p>
<blockquote>
<p>Anyway I am able to achieve the result of <code>#[link]</code> via <code>#[link_args]</code>: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=9f7415ccaefc15c7d471067bed0ce881">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=9f7415ccaefc15c7d471067bed0ce881</a><br>
So <span class="user-mention silent" data-user-id="132721">Tony Arcieri</span>, could you add that to the list? It's an <em>unstable</em> attribute though.</p>
</blockquote>
<p>Actually <code>#[link_args]</code> has been removed now (<a href="https://github.com/rust-lang/rust/issues/83820">#83820</a>)...<br>
Someone who has editing permission may want to remove it from the list.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>